<?$partialLockoutTeams = getPartialLockoutTeams();?>
<script>
function TeamPlayer(id, description, playerType, positionInAFLTeam, team, playerInfo, isLtiReplacement) {
	this.id = id;
	this.description = description;
	this.playerType = playerType;
	this.positionInAFLTeam = positionInAFLTeam;
	this.team = team;
	this.playerInfo = playerInfo;
	this.isLtiReplacement = isLtiReplacement; 
}

var teamPlayers = new Array();
var submittedTeams = new Array();
var partialLockedOutTeams = new Array();
var roundStatus = '<?echo $currentRoundStatus?>';
var KPPCount = 0;
var halfKPPCount = 0;
function validateKPP(frm) {
	var defCount = 0;
	KPPCount = 0;
	halfKPPCount = 0;
		
	checkKPPs(frm, 'LBP');
	checkKPPs(frm, 'FB');
	checkKPPs(frm, 'RBP');
	checkKPPs(frm, 'LHBF');
	checkKPPs(frm, 'CHB');
	checkKPPs(frm, 'RHBF');
	
	if (halfKPPCount <= 2) {
		defCount = KPPCount + halfKPPCount*0.5;
	}
	else {
		defCount = KPPCount + 1;
	}
	
	checkKPPs(frm, 'LFP');
	checkKPPs(frm, 'FF');
	checkKPPs(frm, 'RFP');
	checkKPPs(frm, 'LHFF');
	checkKPPs(frm, 'CHF');
	checkKPPs(frm, 'RHFF');
	
	if (halfKPPCount <= 2) {
		KPPCount += halfKPPCount*0.5;
	}
	else {
		KPPCount++;
	}
	
	if (KPPCount < 4) {
		if (!confirm("Warning: Your KPP count only comes to " + KPPCount + ". Do you want to continue?")) {
			return;
		}
	}
	if (defCount < 2) {
		if (!confirm("Warning: Your Defender KPP count only comes to " + defCount)) {
			return;
		}
	}
	
	validateForm(frm);
}
function checkKPPs(frm, position) {
	if (document.getElementById(position).options[document.getElementById(position).selectedIndex].value != "-1") {
		var player = getPlayer(document.getElementById(position).options[document.getElementById(position).selectedIndex].value);
		if (player.playerType == "KPP" || player.playerType == "KPP_RUCK") {
			KPPCount++;
		}
		if (player.playerType == "HALF_KPP") {
			halfKPPCount++;
		}
	}
}

function getPlayer(playerId) {
	var player = null;
	for (i = 0; i < teamPlayers.length; i++) {
		if (teamPlayers[i].id == playerId) {
			player = teamPlayers[i];
			break;
		}
	}
	
	return player;
}

function displayPlayer(frm, position) {
	var player = null;
	playerId = frm.elements[position].options[frm.elements[position].selectedIndex].value;
	player = getPlayer(playerId);
	
	var color = null;
	if (player != null) {
		if (player.playerType == null || player.playerType == "") {
			color = "black";
		}
		else if (player.playerType == "KPP") {
			color = "blue";
		}
		else if (player.playerType == "KPP_RUCK") {
			color = "red";
		}
		else if (player.playerType == "RUCK") {
			color = "purple";
		}
		else if (player.playerType == "HALF_KPP") {
			color = "green";
		}
		
		var playerString = "";
                if (navigator.appName == 'Microsoft Internet Explorer') {
                playerString = "<span class=\"SimpleTip\" onmouseover=\"javascript:this.className='SimpleTipHover'\" onmouseout=\"javascript:this.className='SimpleTip'\"><img src=\"../../../images/info.jpg\" width=\"15px\" height=\"15px\"><div>" + player.playerInfo + "</div></span>&nbsp;";
                }
                else {
                playerString = "<a href=\"#\" onmouseover=\"this.style.color = '#D17E62'; domTT_activate(this, event, 'content', '" + player.playerInfo.replace("'", "\\'") + "', 'trail', true, 'fade', 'both', 'fadeMax', 87, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><img src=\"../../../images/info.jpg\" width=\"15px\" height=\"15px\"></a>&nbsp;"; 
}
		if (color != null) {
			playerString += "<font color='" + color + "'>" + player.description + "</font>";
		}
		else {
			playerString += player.description;
		}
		if (player.isLtiReplacement) {
		    playerString += " <b>**</b>";
	    }
                if (player.positionInAFLTeam != '') {
                	if (player.positionInAFLTeam == 'EXB') {
						playerString += "&nbsp;<img src='../../../images/yellow-square.JPG'>";                		
                	}
                	else if (player.positionInAFLTeam == 'EMG') {
						playerString += "&nbsp;<img src='../../../images/blue-square.JPG'>";                		
                	}
                	else {
						playerString += "&nbsp;<img src='../../../images/green-square.JPG'>";                		
                	}
		}
                else if (isTeamSubmitted(player.team)) {
                        playerString += "&nbsp;<img src='../../../images/red-square.JPG'>";
                }
		
		if (roundStatus == '<?echo RoundStatusType::Open?>' || (roundStatus == '<?echo RoundStatusType::Partial_Lockout?>' && !isTeamPartiallyLockedOut(player.team))) {
			playerString += "<input type=\"button\" value=\"Edit\" onclick=\"showSelect('" + position + "')\">";
		}
		
		document.getElementById(position + "Div").innerHTML = playerString;
		document.getElementById(position + "Div").style.display = "block";
		document.getElementById(position + "Select").style.display = "none";
	} 
}

function getPlayerInfo(playerInfo) {
   if (navigator.appName == 'Microsoft Internet Explorer') {
	   document.write("<span class=\"SimpleTip\" onmouseover=\"javascript:this.className='SimpleTipHover'\" onmouseout=\"javascript:this.className='SimpleTip'\"><img src=\"../../../images/info.jpg\" width=\"15px\" height=\"15px\"><div>" + playerInfo + "</div></span>&nbsp;");
   }
   else {
       document.write("<a href=\"#\" onmouseover=\"this.style.color = '#D17E62'; domTT_activate(this, event, 'content', '" + playerInfo.replace("'", "\\'") + "', 'trail', true, 'fade', 'both', 'fadeMax', 87, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><img src=\"../../../images/info.jpg\" width=\"15px\" height=\"15px\"></a>&nbsp;"); 
   }
}
function initPlayers(frm) {
	displayPlayer(frm, 'LBP');
	displayPlayer(frm, 'FB');
	displayPlayer(frm, 'RBP');
	displayPlayer(frm, 'LHBF');
	displayPlayer(frm, 'CHB');
	displayPlayer(frm, 'RHBF');
	displayPlayer(frm, 'LW');
	displayPlayer(frm, 'C');
	displayPlayer(frm, 'RW');
	displayPlayer(frm, 'LHFF');
	displayPlayer(frm, 'CHF');
	displayPlayer(frm, 'RHFF');
	displayPlayer(frm, 'LFP');
	displayPlayer(frm, 'FF');
	displayPlayer(frm, 'RFP');
	displayPlayer(frm, 'R');
	displayPlayer(frm, 'F1');
	displayPlayer(frm, 'F2');
	displayPlayer(frm, 'E1');
	displayPlayer(frm, 'E2');
	displayPlayer(frm, 'E3');
	displayPlayer(frm, 'E4');
	displayPlayer(frm, 'E5');
}
function showSelect(position) {
	document.getElementById(position + 'Div').style.display = "none";
	document.getElementById(position + 'Select').style.display = "block";
}
function isTeamSubmitted(team) {
   for (i = 0; i < submittedTeams.length; i++) {
      if (submittedTeams[i] == team) {
         return true;
      }
   }

   return false;
}

function isTeamPartiallyLockedOut(team) {
   for (i = 0; i < partialLockedOutTeams.length; i++) {
      if (partialLockedOutTeams[i] == team) {
         return true;
      }
   }

   return false;
}
<?php
$submittedTeams = getTeamsSubmitted(getCurrentRound());
$countSubmittedTeams = count($submittedTeams);
for ($n = 0; $n < $countSubmittedTeams; $n++) {
?>
submittedTeams[<?echo $n?>] = "<?echo $submittedTeams[$n]?>";
<?
}
$countPartialLockedOutTeams = count($partialLockoutTeams);
for ($n = 0; $n < $countPartialLockedOutTeams; $n++) {
?>
partialLockedOutTeams[<?echo $n?>] = "<?echo $partialLockoutTeams[$n]?>";
<?
}
$myTeam = new SelectedTeam(getSelectedTeamForCurrentRound($loggedInTeam->id), $loggedInTeam->teamName);
$myTeam->id = $loggedInTeam->id;
$ltiReplacements = $myTeam->getLtiReplacements();
$players = $myTeam->getPlayers();
$currentRound = getCurrentRound();
$count = count($players);
for ($i = 0; $i < $count; $i++) {?>
	teamPlayers[<?echo $i?>] = new TeamPlayer('<?echo $players[$i]->player->id?>', "<?echo $players[$i]->player->getDescription()?>", '<?echo $players[$i]->player->playerType?>', '<?echo $players[$i]->positionInAFLTeam?>', '<?echo $players[$i]->player->team?>', "<?echo $players[$i]->playerInfo?>", <?echo $players[$i]->isLtiReplacement?>); 
<?}?>
function showRemoveLti(ltiId, playerOneId, playerOneDescription, playerTwoId, playerTwoDescription) {
	document.getElementById('playerOne').innerHTML = playerOneDescription;
	document.getElementById('playerTwo').innerHTML = playerTwoDescription;
	document.getElementById('ltiId').value = ltiId;
	document.getElementById('playerOneRadio').value = playerOneId;
	document.getElementById('playerTwoRadio').value = playerTwoId;
	document.getElementById('removeLti').style.display = "block";  
}
</script>
<h1>Round <?echo $currentRound?> Team</h1>
<b>Round Status:</b>&nbsp;&nbsp;<b><font color="red"><?echo $currentRoundStatus?></font></b> 
<form name="selectTeamForm" action="../round/submitSelectedTeam.php">
<table width="100%" cellspacing="10">
	<tr>
		<td align="right" colspan="6"><?echo getPlayerValidityKey();?></td>
	</tr>
	<tr>
		<td width="5%"><b>B:</b>
		<td width="30%"><div id="LBPDiv"></div><div id="LBPSelect"><? echo getSelectString('LBP', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'LBP')"></div></td><td width="2%">|</td>
		<td width="30%"><div id="FBDiv"></div><div id="FBSelect"><? echo getSelectString('FB', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'FB')"></div></td><td width="2%">|</td>
		<td width="30%"><div id="RBPDiv"></div><div id="RBPSelect"><? echo getSelectString('RBP', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'RBP')"></div></td>
	</tr>
	<tr>
		<td><b>HB:</b>			
		<td><div id="LHBFDiv"></div><div id="LHBFSelect"><? echo getSelectString('LHBF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'LHBF')"></div></td><td>|</td>
		<td><div id="CHBDiv"></div><div id="CHBSelect"><? echo getSelectString('CHB', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'CHB')"></div></td><td>|</td>
		<td><div id="RHBFDiv"></div><div id="RHBFSelect"><? echo getSelectString('RHBF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'RHBF')"></div></td>
	</tr>			
	<tr>
		<td><b>C:</b>			
		<td><div id="LWDiv"></div><div id="LWSelect"><? echo getSelectString('LW', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'LW')"></div></td><td>|</td>
		<td><div id="CDiv"></div><div id="CSelect"><? echo getSelectString('C', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'C')"></div></td><td>|</td>
		<td><div id="RWDiv"></div><div id="RWSelect"><? echo getSelectString('RW', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'RW')"></div></td>
	</tr>			
	<tr>
		<td><b>HF:</b>			
		<td><div id="LHFFDiv"></div><div id="LHFFSelect"><? echo getSelectString('LHFF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'LHFF')"></div></td><td>|</td>
		<td><div id="CHFDiv"></div><div id="CHFSelect"><? echo getSelectString('CHF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'CHF')"></div></td><td>|</td>
		<td><div id="RHFFDiv"></div><div id="RHFFSelect"><? echo getSelectString('RHFF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'RHFF')"></div></td>
	</tr>			
	<tr>
		<td><b>F:</b>			
		<td><div id="LFPDiv"></div><div id="LFPSelect"><? echo getSelectString('LFP', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'LFP')"></div></td><td>|</td>
		<td><div id="FFDiv"></div><div id="FFSelect"><? echo getSelectString('FF', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'FF')"></div></td><td>|</td>
		<td><div id="RFPDiv"></div><div id="RFPSelect"><? echo getSelectString('RFP', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'RFP')"></div></td>
	</tr>			
	<tr>
		<td><b>R:</b>			
		<td><div id="RDiv"></div><div id="RSelect"><? echo getSelectString('R', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'R')"></div></td><td>|</td>
		<td><div id="F1Div"></div><div id="F1Select"><? echo getSelectString('F1', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'F1')"></div></td><td>|</td>
		<td><div id="F2Div"></div><div id="F2Select"><? echo getSelectString('F2', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'F2')"></div></td>
	</tr>
	<tr>
		<td><b>EMG:</b>			
		<td><div id="E1Div"></div><div id="E1Select"><? echo getSelectString('E1', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'E1')"></div></td><td>|</td>
		<td><div id="E2Div"></div><div id="E2Select"><? echo getSelectString('E2', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'E2')"></div></td><td>|</td>
		<td><div id="E3Div"></div><div id="E3Select"><? echo getSelectString('E3', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'E3')"></div></td>
	</tr>
	<tr>
		<td><b></b>			
		<td><div id="E4Div"></div><div id="E4Select"><? echo getSelectString('E4', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'E4')"></div></td><td>|</td>
		<td><div id="E5Div"></div><div id="E5Select"><? echo getSelectString('E5', $players, $myTeam, $currentRoundStatus, $partialLockoutTeams);?><input type="button" value="Set" onclick="displayPlayer(document.forms['selectTeamForm'], 'E5')"></div></td><td></td>
		<td></td>
	</tr>		
	<tr>
		<td valign="top"><b>RES:</b></td>
		<td colspan="7">
		<?
		$ltis = $myTeam->getLti();
		$ltiCount = count($ltis);
				
		$reserves = $myTeam->getReserves();
		$count = count($reserves);
		for ($i = 0; $i < $count; $i++) {
			if ($i > 0) {
				echo " | ";
			}
			?><script>getPlayerInfo('<?echo str_replace("'", "\'", $reserves[$i]->playerInfo);?>');</script><?echo "&nbsp;" . getPlayerDisplay($reserves[$i], $currentRound);
		}
		?>
		</td>
	</tr>
	<?if ($ltiCount > 0) {?>	
	<tr>
		<td><b>LTI:</b></td>
		<td colspan="7">
		<?
		for ($k = 0; $k < $ltiCount; $k++) {
			if ($k > 0) {
				echo ", ";
			}
			?><script>getPlayerInfo("<?echo str_replace("'", "\'", $ltis[$k]->playerInfo);?>");</script><?echo "&nbsp;" . getPlayerDisplay($ltis[$k], $currentRound);
			$lti = getLtiSpudEntry($ltiList, $ltis[$k]->player);
			?><input type="button" value="Remove" onclick="showRemoveLti(<?echo $lti->id . ", " . $lti->playerOne->id . ", '" . str_replace("'", "\'", $lti->playerOne->getDescription()) . "', " . $lti->playerTwo->id . ", '" . str_replace("'", "\'", $lti->playerTwo->getDescription()) . "'";?>)">
			<?
		}
		?>
		</td>
	</tr>
	<tr>
		<td></td>
		<td>
		<div id="removeLti" style="display: none">
			<br>
			<table>
				<tr>
					<td colspan="2"><b>Select the player you wish to put back on the APL</b></td>
				</tr>
				<tr>
					<td><span id="playerOne"></span><input type="radio" name="playerToReturn" id="playerOneRadio"></td><td><span id="playerTwo"></span><input type="radio" name="playerToReturn" id="playerTwoRadio" checked></td>
				</tr>
				<tr>
					<td><input type="button" value="Submit" onclick="submitRemoveLti()"></td>
				</tr>
			</table>
			</form>	
		</div>
		</td>
	</tr>
	<?}?>
	<?if ($currentRoundStatus != RoundStatusType::Lockout) {?>	
	<tr>
		<td><input type="button" value="Update" onclick="validateKPP(document.forms['selectTeamForm'])" class="buttonStyle"></td>
	</tr>
	<?}?>			
</table>
</form>
<form name="removeLtiForm" id="removeLtiForm" action="../round/removeLti.php" method="post">
<input type="hidden" id="ltiId" name="ltiId">
<input type="hidden" name="playerToReturnId">
</form>
<script>
function submitRemoveLti() {
	if (document.getElementById('playerOneRadio').checked) {
		document.removeLtiForm.playerToReturnId.value = document.getElementById('playerOneRadio').value; 
	}
	else {
		document.removeLtiForm.playerToReturnId.value = document.getElementById('playerTwoRadio').value;
	}
	document.removeLtiForm.submit();
}
</script>

<script>initPlayers(document.forms['selectTeamForm']);</script>